package methodEmbedding.Standing_Ovation.S.LYD1849;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class EN2015QA {
	public static void main(String[] args) {
		File inputFile = new File("c:/tmp/A-small-attempt1.in");
		File outputFile = new File("c:/tmp/A-small-attempt1.out");
		FileReader filereader = null;
		BufferedReader br = null;
		FileWriter filewriter = null;
		BufferedWriter bw = null;

		try {
			// ??????
			filereader = new FileReader(inputFile);
			br = new BufferedReader(filereader);

			// ??????
			filewriter = new FileWriter(outputFile);
			bw = new BufferedWriter(filewriter);

			/**************************************************************************************
			// ????????????????????????????????????
			 **************************************************************************************/
			int T;

			// ???????????????????????????
			String lineStr = br.readLine();
			T = Integer.parseInt(lineStr);
			System.out.println("T = " + T + "\n");

			/**************************************************************************************
			// Case???1???????????????
			 **************************************************************************************/
			long caseIndex = 1;
			for(int t=0; t < T; t++) {
				/**************************************************************************************
				// Case?????????
				 **************************************************************************************/
				// ??????
				int caseAnser = -1;

				// Smax???????????????
				int Smax = 0;

				lineStr = br.readLine();
				String line[] = lineStr.split(" ");
				Smax = Integer.parseInt(line[0]);

				System.out.println("Smax = " + Smax);

				String digitString = line[1];
				System.out.println(digitString);


//				int Si[] = new int[1001];
				int Si = -1;

				// ????????????????????????
				int stoodAudience = 0;

				// ??????
				int friends = 0;

				for(int i=0; i<Smax+1; i++){
					// Si???????????????
					Si = Integer.parseInt(digitString.substring(i, i+1));
//					System.out.println("Si[" + i + "] = " + Si[i]);

					if(Si != 0) {
						// Si??????????????????????????????????????????
						if(stoodAudience >= i){
							// ????????????????????????????????????????????????????????????????????????????????????
							stoodAudience = stoodAudience + Si;
							//						System.out.println(stoodAudience);
						} else {
							// ????????????????????????
							friends = friends + (i - stoodAudience);

							// ????????????????????????????????????????????????????????? ??? ?????? ??? ???????????????
							stoodAudience = stoodAudience + friends + Si;
							//						System.out.println("friends = " + friends);
						}
					}
				}

				caseAnser = friends;

				/**************************************************************************************
				// Case?????????
				 **************************************************************************************/
				String output = "Case #" + caseIndex + ": " + caseAnser;
				caseIndex++;
				System.out.println(output);
				bw.write(output);
				bw.newLine();
				bw.flush();

				/**************************************************************************************
				// ??????Case???????????????
				 **************************************************************************************/
				System.out.println();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}

			try {
				if (filereader != null) {
					filereader.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}

			try {
				if (bw != null) {
					bw.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}

			try {
				if (filewriter != null) {
					filewriter.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
